package de.jabc.sib.bio.ebi;

import de.jabc.adapter.bio.ebi.Branches;
import de.jabc.adapter.bio.ebi.LightweightServiceAdapter;
import de.jabc.adapter.bio.ebi.ServiceAdapter;
import de.metaframe.jabc.framework.execution.ExecutionEnvironment;
import de.metaframe.jabc.framework.sib.annotation.SIBClass;
import de.metaframe.jabc.framework.sib.annotation.SIBStatus;
import de.metaframe.jabc.framework.sib.parameter.ContextExpression;
import de.metaframe.jabc.framework.sib.parameter.ContextKey;
import de.metaframe.jabc.sib.ServiceAdapterDescriptor;

/**
 * Calls the EBI's EMBOSS Readseq service.
 * 
 * Readseq reads and converts biosequences between a selection of common
 * biological sequence formats, including EMBL, GenBank and fasta sequence
 * formats.
 * 
 * @param email
 *            - user email
 * @param title
 *            - job title
 * @param inputformat
 *            - sequence format for input data
 * @param outputformat
 *            - sequence format for output data. Default is EBML (value 4).
 * @param outputcase
 *            - input sequence data to process
 * @param reverse
 *            - output reverse complement of input nucleotide sequence
 * @param degap
 *            - remove gap symbols from sequence
 * @param transymbol
 *            - replace specified base/residue symbol(s) in input sequence with
 *            specified base/residue symbol(s)
 * @param feature
 *            - list of selected features to process
 * @param fthandle
 *            - action to perform on selected features
 * @param subrange
 *            - region of input sequence on which feature processing is
 *            performed
 * @param sequence
 *            - input sequence data to process
 * @param result
 *            - converted sequence
 * 
 * @author naviator.dev
 * 
 */

@SIBClass("ebi-sibs/Readseq")
@SIBStatus("IMPLEMENTED")
public class Readseq extends AbstractSIB {

	/* Branches */
	public static final String[] BRANCHES = { Branches.DEFAULT, Branches.ERROR };

	/* Parameters */
	public ContextExpression Email = new ContextExpression("${email}",
			String.class, false);
	public ContextExpression Title = new ContextExpression("", String.class,
			false);
	public ContextExpression Inputformat = new ContextExpression("",
			Integer.class, false);
	public ContextExpression Outputformat = new ContextExpression("4",
			Integer.class, false);
	public ContextExpression Outputcase = new ContextExpression("",
			String.class, false);
	public ContextExpression Reverse = new ContextExpression("", Boolean.class,
			false);
	public ContextExpression Degap = new ContextExpression("", String.class,
			false);
	public ContextExpression Transymbol = new ContextExpression("",
			String.class, false);
	public ContextExpression Feature = new ContextExpression("", String.class,
			false);
	public ContextExpression Fthandle = new ContextExpression("", String.class,
			false);
	public ContextExpression Subrange = new ContextExpression("", String.class,
			false);
	public ContextExpression Sequence = new ContextExpression("${sequence}",
			String.class, false);
	public ContextKey result = new ContextKey("result", ContextKey.Scope.LOCAL,
			true);

	@Override
	public String execute(ExecutionEnvironment environment) {
		try {
			return ServiceAdapter.callReadseq(environment, this.Email,
					this.Title, this.Inputformat, this.Outputformat,
					this.Outputcase, this.Reverse, this.Degap, this.Transymbol,
					this.Feature, this.Fthandle, this.Subrange, this.Sequence,
					this.result);
		} catch (NoClassDefFoundError e) {
			return Branches.ERROR;
		}
	}

	@Override
	public ServiceAdapterDescriptor generate() {
		return new ServiceAdapterDescriptor(
				LightweightServiceAdapter.class.getName(), "callReadseq",
				"Email", "Title", "Inputformat", "Outputformat", "Outputcase",
				"Reverse", "Degap", "Transymbol", "Feature", "Fthandle",
				"Subrange", "Sequence", "result");
	}

}
